<?php
$id = $_GET['id'];
$blog = $_GET['blog'];

if($_SESSION['pseudo'] != '')
$pseudo = $_SESSION['pseudo'];
elseif($_COOKIE['pseudo'] != '')
$pseudo = $_COOKIE['pseudo'];

include_once("../includes/config.php");

$pseudo = mysql_real_escape_string($pseudo);
$blog = mysql_real_escape_string($blog);
$retour = mysql_query('SELECT * FROM newsletter_membres WHERE pseudo="'.$pseudo.'"');
$donnees = mysql_fetch_array($retour);
$password = $donnees['api'];

if($donnees['verifmail'] == "1")
$email = $donnees['email'];
else
{
include_once("../../libs/skyrock.class.php");
$skyrock = new skyrock('#'.$pseudo, $password);
$info = $skyrock->getUserInfos(1);
$email = $info['email'];
}
$email = mysql_real_escape_string($email);

$retour = mysql_query('SELECT count(*) FROM newsletter_abonnes WHERE email="'.$email.'" AND newsletter="'.$blog.'"') or die(mysql_error());
$resultat=mysql_fetch_row($retour); 
$nb_abonnement = $resultat[0];

if($nb_abonnement == 0)
{
$validation = mysql_real_escape_string(1);
mysql_query("INSERT INTO newsletter_abonnes VALUES('', '$email','$blog', '$validation')") or die(mysql_error());
//echo 'Inscription OK';
header('Location: index.html?register=ok&blog='.$blog);
}
else
{
header('Location: index.html?register=ko&blog='.$blog);
//echo 'Vous êtes déjà inscrit';
}
?>